const crypto = require('crypto');

// 生成班级码
function generateClassCode(length = 6) {
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  let code = '';
  for (let i = 0; i < length; i++) {
    code += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  return code;
}

// 生成JWT token
function generateToken(userId) {
  const jwt = require('jsonwebtoken');
  return jwt.sign(
    { userId },
    process.env.JWT_SECRET || 'ivory-tower-secret-key-2024',
    { expiresIn: '7d' }
  );
}

module.exports = {
  generateClassCode,
  generateToken
};